<template>
	<div class="paper-wrap">
		<n-card>
			<!-- 学生信息 -->
			<div class="paper-title">
				<h2>震动法测材料的杨氏模量</h2>
				<div class="stu-info">
					<div class="stu-info-item">
						<span>学号：</span>
						<span>{{ sid }}</span>
					</div>
					<div class="stu-info-item">
						<span>姓名：</span>
						<span>{{ name }}</span>
					</div>
					<div class="stu-info-item">
						<span>班级：</span>
						<span>{{ college }}学院 {{ major }}专业 {{ grade }}级 {{ classnum }} 班</span>
					</div>
				</div>
			</div>
			<!-- 实验的基本信息 -->
			<n-divider title-placement="left">
				<h2>一、实验目的</h2>
			</n-divider>
			<div class="paper-purpose">
				<ol>
					<li>
						1.理解悬丝合弯曲共振法测量金属材料杨氏模量的基本原理。
					</li>
					<li> 2.理解真假共振峰的辨别方法。 </li>
					<li> 3.掌握示波器的使用方法。 </li>
				</ol>
			</div>
			<n-divider title-placement="left">
				<h2>二、实验仪器</h2>
			</n-divider>
			<div class="paper-instrument">
				<p class="instruments">本实验的实验装置有:DYM-I型动力学杨氏模量实验仪、信号发生器、示波器、锡棒、电子天平、游标卡尺等。
				</p>
			</div>
			<n-divider title-placement="left">
				<h2>三、实验原理</h2>
			</n-divider>
			<div class="paper-principle">
				<p class="principles"> 具体内容请参照实验指导书进行学习 </p>
			</div>

			<n-divider title-placement="left">
				<h2>四、数据记录与处理</h2>
			</n-divider>
			<div class="paper-data">
				<!-- 第一个表单 -->
				<h3>(一) 基本量测量 </h3>
				<el-form :form="model" style="font-size: 19px" label-width="160px" label-position="left">
					<el-form-item label="金属铜杆的长度L=" style="width: 35%">
						<span style="font-size: 16px">{{ model[0].value }}</span>&emsp;<span style="font-size: 12px">{{model[0].timeStamp }}</span>
					</el-form-item>
					<el-form-item label="金属铜杆的直径d=" style="width: 35%">
						<span style="font-size: 16px">{{ model[1].value }}</span>&emsp;<span style="font-size: 12px">{{
							model[1].timeStamp }}</span>
					</el-form-item>
					<el-form-item label="金属铜杆的质量m=" style="width: 35%">
						<span style="font-size: 16px">{{ model[2].value }}</span>&emsp;<span style="font-size: 12px">{{ model[2].timeStamp }}</span>
					</el-form-item>
					<el-form-item label="室温t=" style="width: 35%">
						<el-input v-model="model[3].value" @blur="getTime(3)"></el-input><span style="font-size: 16px">{{ model[3].value }}</span>&emsp;<span style="font-size: 12px">{{ model[3].timeStamp }}</span>
					</el-form-item>
				</el-form>
				<!-- 第二个表单 -->
				<h3>(二) 悬挂点的相对位置Xn/L与共振频率Fn的关系 </h3>
				<table border="1" style="
						width: 100%;
						border-collapse: collapse;
						border: 1px solid #000;
					">
					<tr style="background: rgb(0, 0, 0, 0.1)">
						<td>悬挂点的个数n</td>
						<td>1</td>
						<td>2</td>
						<td>3</td>
						<td>4</td>
						<td>5</td>
						<td>6</td>
					</tr>
					<tr>
						<th>悬挂点距端面的距离Xn/mm</th>
						<td>
					<span style="font-size: 16px">{{ model[4].value }}</span>&emsp;<span style="font-size: 12px">{{ model[4].timeStamp }}</span>
						</td>
						<td>
					<span style="font-size: 16px">{{ model[5].value }}</span>&emsp;<span style="font-size: 12px">{{ model[5].timeStamp }}</span>
						</td>
						<td>
					<span style="font-size: 16px">{{ model[6].value }}</span>&emsp;<span style="font-size: 12px">{{ model[6].timeStamp }}</span>
						</td>
						<td>
					<span style="font-size: 16px">{{ model[7].value }}</span>&emsp;<span style="font-size: 12px">{{ model[7].timeStamp }}</span>
						</td>
						<td>
					<span style="font-size: 16px">{{ model[8].value }}</span>&emsp;<span style="font-size: 12px">{{ model[8].timeStamp }}</span>
						</td>
						<td>
					<span style="font-size: 16px">{{ model[9].value }}</span>&emsp;<span style="font-size: 12px">{{ model[9].timeStamp }}</span>
						</td>
					</tr>
					<tr>
						<th>第n个悬挂点的Xn/L</th>
						<td>
							<span style="font-size: 16px">{{ model[10].value }}</span>&emsp;<span style="font-size: 12px">{{ model[10].timeStamp }}</span>
						</td>
						<td>
							<span style="font-size: 16px">{{ model[11].value }}</span>&emsp;<span style="font-size: 12px">{{ model[11].timeStamp }}</span>
						</td>
						<td>
							<span style="font-size: 16px">{{ model[12].value }}</span>&emsp;<span style="font-size: 12px">{{ model[12].timeStamp }}</span>
						</td>
						<td>
							<span style="font-size: 16px">{{ model[13].value }}</span>&emsp;<span style="font-size: 12px">{{ model[13].timeStamp }}</span>
						</td>
						<td>
							<span style="font-size: 16px">{{ model[14].value }}</span>&emsp;<span style="font-size: 12px">{{ model[14].timeStamp }}</span>
						</td>
						<td>
							<span style="font-size: 16px">{{ model[15].value }}</span>&emsp;<span style="font-size: 12px">{{ model[15].timeStamp }}</span>
						</td>
					</tr>
					<tr>
						<th>共振频率值fn/Hz</th>
						<td>
							<span style="font-size: 16px">{{ model[16].value }}</span>&emsp;<span style="font-size: 12px">{{ model[16].timeStamp }}</span>
						</td>
						<td>
							<span style="font-size: 16px">{{ model[17].value }}</span>&emsp;<span style="font-size: 12px">{{ model[17].timeStamp }}</span>
						</td>
						<td>
							<span style="font-size: 16px">{{ model[18].value }}</span>&emsp;<span style="font-size: 12px">{{ model[18].timeStamp }}</span>
						</td>
						<td>
							<span style="font-size: 16px">{{ model[19].value }}</span>&emsp;<span style="font-size: 12px">{{ model[19].timeStamp }}</span>
						</td>
						<td>
							<span style="font-size: 16px">{{ model[20].value }}</span>&emsp;<span style="font-size: 12px">{{ model[20].timeStamp }}</span>
						</td>
						<td>
							<span style="font-size: 16px">{{ model[21].value }}</span>&emsp;<span style="font-size: 12px">{{ model[21].timeStamp }}</span>
						</td>
					</tr>
				</table>
				<!-- 第三个表单 -->
				<h3>(三) 用作图法确定共振基频频率f </h3>
				<p>画出悬挂点相对位置z/L 与共振频率的关系</p>
				<!-- <p
					>由所作曲线可知，金属铜棒距端面 0.224L 点的共振基频频率f=
					<el-input
						type="text"
						v-model="model[16].value"
						@blur="getTime(16)"
					/>
				</p> -->
				<el-form-item label="由所作曲线可知，金属铜棒距端面 0.224L 点的共振基频频率f=" style="width: 60%">
					<span style="font-size: 16px">{{ model[22].value }}</span>&emsp;<span style="font-size: 12px">{{ model[22].timeStamp }}</span>
				</el-form-item>
				<!-- <p
					>杨氏模量 E=
					<el-input
						type="text"
						v-model="model[16].value"
						@blur="getTime(16)"
					/>
				</p> -->
				<el-form-item label="杨氏模量 E=" style="width: 60%">
					<span style="font-size: 16px">{{ model[23].value }}</span>&emsp;<span style="font-size: 12px">{{ model[23].timeStamp }}</span>
				</el-form-item>
			</div>
			<!-- 第五个表单 -->
			<n-divider title-placement="left">
				<h2>五、实验分析</h2>
			</n-divider>
			<div class="paper-analyze">
				<div style="margin-bottom: 10px; font-size: 17px">1.材料的固有频率值取决于</div>
				<span style="font-size: 16px">{{ model[24].value }}</span>&emsp;<span style="font-size: 12px">{{ model[24].timeStamp }}</span>
				<div style="margin-bottom: 10px; font-size: 17px">2. 你在实验过程中是如何判断共振峰的真假的?</div>
				<span style="font-size: 16px">{{ model[25].value }}</span>&emsp;<span style="font-size: 12px">{{ model[25].timeStamp }}</span>
			</div>
			<div class="button" style="display: flex">
				<el-button type="primary" @click="exOk()">通过</el-button>
				<el-button type="success" @click="exFix()">需要修改</el-button>
			</div>
		</n-card>
	</div>
</template>
<script setup lang="ts">
//@ts-nocheck
// 关闭ts检查
import { useRoute} from 'vue-router'
import { getDetailEx, changeState } from '@/api/request'
const route = useRoute()
// 试卷头的基本信息
// 使用onMounted生命周期函数
const jwtToken = localStorage.getItem('jwtToken')

onMounted(() => {
	getDetailEx(jwtToken, eid, rid).then((res) => {
		console.log(res.data.data[0], 'socket数据')
		model.value.forEach((element) => {
			var obj = element
			var kid = obj.kid
			if (res.data.data[0].hasOwnProperty(kid)) {
				obj.value = res.data.data[0][kid]
				obj.timeStamp = res.data.data[0]['t' + kid]
			}
		})
		console.log('处理后', model.value)
	})
})
const store=useGlobalStore()
const sid = route.query.sid
const rid = route.query.rid
const eid = route.query.eid
const name = route.query.name
const classnum=route.query.classNum
const college=route.query.college
const grade=route.query.grade
const major=route.query.major
import { useGlobalStore } from "../../../store/GlobalStore";
const tid=store.userInfo.tid
const ws = new WebSocket(`ws://210.44.37.172:8082/message?id=${tid}&role=teacher`)
ws.onopen = function (e) {
	console.log('连接成功')
}
ws.onmessage = function (e) {
	console.log(e.data, '接收返回的消息')
	console.log(JSON.parse(e.data), '解析一下的数据')
	if (JSON.parse(e.data).rid == rid) {
		model.value.forEach((element) => {
			if (element.kid == JSON.parse(e.data).kid) {
				element.value = JSON.parse(e.data).value
				element.timeStamp = JSON.parse(e.data).timeStamp
			}
		})
	}
}
ws.onclose = function () {
	console.log('连接关闭')
}
ws.onerror = function () {
	console.log('连接出错')
}
// 学生填的值
// 实验通过
const exOk = () => {
	changeState(jwtToken, rid, 3).then((res) => {
		console.log(res)
		console.log("rid",rid);
		
		ElMessage.success('已通过')
	})
}
const exFix = () => {
	changeState(jwtToken, rid, 1).then((res) => {
		console.log(res)
		ElMessage.success('反馈成功')
	})
}

const model = ref([
	{ kid: 'k1', value: '', timeStamp: '' },
	{ kid: 'k2', value: '', timeStamp: '' },
	{ kid: 'k3', value: '', timeStamp: '' },
	{ kid: 'k4', value: '', timeStamp: '' },
	{ kid: 'k5_1', value: '', timeStamp: '' },
	{ kid: 'k5_2', value: '', timeStamp: '' },
	{ kid: 'k5_3', value: '', timeStamp: '' },
	{ kid: 'k5_4', value: '', timeStamp: '' },
	{ kid: 'k5_5', value: '', timeStamp: '' },
	{ kid: 'k5_6', value: '', timeStamp: '' },
	{ kid: 'k6_1', value: '', timeStamp: '' },
	{ kid: 'k6_2', value: '', timeStamp: '' },
	{ kid: 'k6_3', value: '', timeStamp: '' },
	{ kid: 'k6_4', value: '', timeStamp: '' },
	{ kid: 'k6_5', value: '', timeStamp: '' },
	{ kid: 'k6_6', value: '', timeStamp: '' },
	{ kid: 'k7_1', value: '', timeStamp: '' },
	{ kid: 'k7_2', value: '', timeStamp: '' },
	{ kid: 'k7_3', value: '', timeStamp: '' },
	{ kid: 'k7_4', value: '', timeStamp: '' },
	{ kid: 'k7_5', value: '', timeStamp: '' },
	{ kid: 'k7_6', value: '', timeStamp: '' },
	{ kid: 'k8', value: '', timeStamp: '' },
	{ kid: 'k9', value: '', timeStamp: '' },
	{ kid: 'k10', value: '', timeStamp: '' },
	{ kid: 'k11', value: '', timeStamp: '' },
])

</script>

<style lang="less" scoped>
.paper-title {
	.stu-info {
		display: flex;
		align-items: center;

		.stu-info-item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin: 10px;
		}
	}
}

.form1 {
	.form-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: 10px;

		.input-group {
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 100%;

			.input {
				width: 100%;
			}
		}
	}
}

table {
	margin: 10px;

	tr {
		td {
			text-align: center;
			padding: 10px;

			input {
				width: 100%;
				height: 100%;
				border: none;
				outline: none;
				text-align: center;
				box-sizing: border-box;

				&:focus {
					border-radius: 5px;
					border: 1px solid #000;
				}
			}
		}
	}
}

.btn-group {
	// 右下角
	display: flex;
	align-items: flex-end;
	justify-content: flex-end;
	margin: 10px;

	.n-button {
		margin-left: 10px;
	}
}
</style>
